package com.ajk.server.service.impl;
import java.util.List;

import org.apache.commons.collections4.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.ajk.server.dao.TestQuestionItemMapper;
import com.ajk.server.model.TestQuestionItem;
import com.ajk.server.model.query.TestQuestionItemQuery;
import com.ajk.server.service.TestQuestionItemService;

/**
 * 测试题目选项  <br>
 * t_test_question_item <br>
 * v1.0 2016-05-01
 */
 @Service
 public class TestQuestionItemServiceImpl implements TestQuestionItemService {
	
	private static final Logger logger = LoggerFactory.getLogger(TestQuestionItemServiceImpl.class);
	
	@Autowired
	private TestQuestionItemMapper testQuestionItemMapper;
	
	/**
 	*根据ID删除 测试题目选项
 	*/
 	@Override
 	public Integer deleteTestQuestionItemById(Integer id){
 		return testQuestionItemMapper.deleteById(id);
 	}
 	
 	/**
 	*新增 测试题目选项
 	*/
 	@Override
 	@Transactional
 	public Integer batchInsertTestQuestionItem(List<? extends TestQuestionItem> testQuestionItems){
		Integer count = testQuestionItemMapper.batchInsert(testQuestionItems);
		return count;
 	}
 	/**
 	*新增 测试题目选项
 	*/
 	@Override
 	@Transactional
 	public Integer insertTestQuestionItem(TestQuestionItem domain){
		Integer id = testQuestionItemMapper.insert(domain);
		return id;
 	}

 	/**
 	*更新 测试题目选项
 	*/
 	@Override
 	@Transactional
 	public Integer updateTestQuestionItem(TestQuestionItem domain){
		Integer count = testQuestionItemMapper.update(domain);
		return count;
 	}
 	
 	/**
 	*根据ID查询 测试题目选项
 	*/
 	public TestQuestionItem findTestQuestionItemById(Integer id){
 		TestQuestionItem result = testQuestionItemMapper.findById(id);
 		if(result!=null){
 			result.dealWith();
 		}
 		return result;
 	}

	/**
 	*通过query 查询 测试题目选项
 	*/
	public List<TestQuestionItem> findTestQuestionItemByQuery(TestQuestionItemQuery query){
		query.dealWith();
		List<TestQuestionItem> result = testQuestionItemMapper.findByQuery(query);
		if(CollectionUtils.isNotEmpty(result)) {
			for (TestQuestionItem testQuestionItem : result) {
				testQuestionItem.dealWith();
			}
		}
		return result;
	}	
	
	/**
 	*通过query count总条数
 	*/
 	public Integer countTestQuestionItemByQuery(TestQuestionItemQuery query){
 		query.dealWith();
 		Integer result = testQuestionItemMapper.countByQuery(query);
 		return result;
 	}
 	
 	/**
 	* 通过ids查询
 	*/
 	public List<TestQuestionItem> findTestQuestionItemByIds(List<Integer> ids){
 		List<TestQuestionItem> result = testQuestionItemMapper.findByIds(ids);
		if(CollectionUtils.isNotEmpty(result)) {
			for (TestQuestionItem testQuestionItem : result) {
				testQuestionItem.dealWith();
			}
		}
		return result;
 	}
 	
}	